<?php
class OnlineSupportEditForm extends Form{
	function OnlineSupportEditForm(){
		Form::Form('OnlineSupportEditForm');
		AZLib::get_config();
	}
	
	function on_submit()
	{
		$og_name 	= Url::get('og_name');
		$u_name 	= Url::get('u_name');
		$u_yahoo 	= Url::get('u_yahoo');
		$u_skype 	= Url::get('u_skype');
		
		$OnlineSupport = array();
		
		if($og_name)
		{
			foreach ($og_name as $gid => $g_name)
			{
				if($g_name != '' && isset($u_name[$gid],$u_yahoo[$gid],$u_skype[$gid]))
				{
					$garray = array(
									'name'  => $g_name,
									'users' => array()
									);
									
					foreach ($u_name[$gid] as $uid => $name)
					{
						if($name != '' && isset($u_yahoo[$gid][$uid],$u_skype[$gid][$uid]) && ($u_yahoo[$gid][$uid] != '' || $u_skype[$gid][$uid]!=''))
						{
							$garray['users'][$uid] = array(
															'name' 	=> $name,
															'yahoo' => $u_yahoo[$gid][$uid],
															'skype' => $u_skype[$gid][$uid],
															);
						}
					}
					
					if($garray['users'])
					{
						$OnlineSupport[$gid] = $garray;
					}
				}
			}
		}
		
		if(isset(CGlobal::$configs['OnlineSupport']))
			DB::update('configs',array("conf_val"=>addslashes(serialize($OnlineSupport))),"conf_key='OnlineSupport'", __FILE__." Dòng:".__LINE__);
		else
			DB::insert('configs',array("conf_key"=>'OnlineSupport',"conf_val"=>addslashes(serialize($OnlineSupport))), __FILE__." Dòng:".__LINE__);
		
		AZLib::get_config(0,1);
		
		AZLib::refreshParent();
	}
	
	function draw()
	{
		global $display;
			
		$OnlineSupport = @CGlobal::$configs['OnlineSupport']['conf_val'];
		
		if($OnlineSupport){
			$OnlineSupport = unserialize(stripslashes($OnlineSupport));
		}
		else
		{
			$OnlineSupport = array(		
									array(
												'name' => "",
												'users'=> array(
																array(
																	'yahoo' => '',
																	'skype' => '',
																	)
																)
										)
									);
		}
		
		$display->add("msg",$this->showFormErrorMessages(1));
		
		$display->add("OnlineSupport",$OnlineSupport);
		
		$this->beginForm();
		$display->output("OnlineSupportEdit");
		$this->endForm();
	}
}
?>